package o;

import android.graphics.PointF;
import android.util.DisplayMetrics;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.ActivityChooserView.ActivityChooserViewAdapter;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.j;
import androidx.recyclerview.widget.RecyclerView.q.c;
import androidx.recyclerview.widget.RecyclerView.t;

public class eiy extends mn {
    private boolean ˊ = MinimumFactory.getBoolValue(ContentManager.getInstant().getContext());
    private RecyclerView ˋ;
    private mq ॱ;

    public void ˏ(@Nullable RecyclerView recyclerView) throws IllegalStateException {
        this.ˋ = recyclerView;
        super.ˏ(recyclerView);
    }

    @Nullable
    protected mh ˋ(j jVar) {
        if (jVar instanceof c) {
            return new mh(this, this.ˋ.getContext()) {
                final /* synthetic */ eiy ʼ;

                public void ˋ(View view, t tVar, e eVar) {
                    int[] ˏ = this.ʼ.ˏ(this.ʼ.ˋ.ʻ(), view);
                    int i = ˏ[0];
                    int i2 = ˏ[1];
                    int ˎ = ˎ(Math.max(Math.abs(i), Math.abs(i2)));
                    if (ˎ > 0) {
                        eVar.ˏ(i, i2, ˎ, this.ˎ);
                    }
                }

                protected float ˋ(DisplayMetrics displayMetrics) {
                    return 40.0f / ((float) displayMetrics.densityDpi);
                }
            };
        }
        return null;
    }

    public int[] ˏ(@NonNull j jVar, @NonNull View view) {
        int[] iArr = new int[2];
        if (jVar.ʻ()) {
            iArr[0] = ॱ(view, ˎ(jVar));
        } else {
            iArr[0] = 0;
        }
        return iArr;
    }

    private int ॱ(View view, mq mqVar) {
        if (this.ˊ) {
            return mqVar.ॱ(view) - mqVar.ˊ();
        }
        return mqVar.ˋ(view) - mqVar.ˏ();
    }

    public View ॱ(j jVar) {
        if (jVar instanceof LinearLayoutManager) {
            return ˎ(jVar, ˎ(jVar));
        }
        return null;
    }

    private View ˎ(j jVar, mq mqVar) {
        if (!(jVar instanceof LinearLayoutManager)) {
            return null;
        }
        int ॱˊ = ((LinearLayoutManager) jVar).ॱˊ();
        if (ॱˊ == -1) {
            return null;
        }
        if (((LinearLayoutManager) jVar).ॱˎ() == jVar.ˌ() - 1) {
            return null;
        }
        View ˋ = jVar.ˋ(ॱˊ);
        if (ˋ == null) {
            return null;
        }
        float ʻ;
        if (this.ˊ) {
            ʻ = (((float) mqVar.ʻ()) - ((float) mqVar.ˋ(ˋ))) / ((float) mqVar.ˊ(ˋ));
        } else {
            ʻ = ((float) mqVar.ॱ(ˋ)) / ((float) mqVar.ˊ(ˋ));
        }
        if (ʻ <= 0.5f) {
            return jVar.ˋ(ॱˊ + 1);
        }
        return ˋ;
    }

    private mq ˎ(j jVar) {
        if (this.ॱ == null) {
            this.ॱ = mq.ˏ(jVar);
        }
        return this.ॱ;
    }

    public int ˏ(j jVar, int i, int i2) {
        if (!(jVar instanceof c)) {
            return -1;
        }
        int ˌ = jVar.ˌ();
        if (ˌ == 0) {
            return -1;
        }
        View ॱ = ॱ(jVar);
        if (ॱ == null) {
            return -1;
        }
        int ˎ = jVar.ˎ(ॱ);
        if (ˎ == -1) {
            return -1;
        }
        PointF ˎ2 = ((c) jVar).ˎ(ˌ - 1);
        if (ˎ2 == null) {
            return -1;
        }
        int ˊ;
        int round = Math.round(((float) (jVar.ˋˊ() / ˎ(jVar).ˊ(ॱ))) * 0.67f);
        if (jVar.ʻ()) {
            ˊ = ˊ(jVar, ˎ(jVar), i, 0);
            if (ˊ > round) {
                ˊ = round;
            }
            if (ˊ < (-round)) {
                ˊ = -round;
            }
            if (ˎ2.x < 0.0f) {
                ˊ = -ˊ;
            }
        } else {
            ˊ = 0;
        }
        if (ˊ == 0) {
            return -1;
        }
        ˊ += ˎ;
        if (ˊ < 0) {
            ˊ = 0;
        }
        if (ˊ >= ˌ) {
            return ˌ - 1;
        }
        return ˊ;
    }

    private int ˊ(j jVar, mq mqVar, int i, int i2) {
        int[] ˏ = ˏ(i, i2);
        float ˊ = ˊ(jVar, mqVar);
        if (ˊ <= 0.0f) {
            return 0;
        }
        int i3 = ˏ[0];
        if (i3 > 0) {
            return (int) Math.floor((double) (((float) i3) / ˊ));
        }
        return (int) Math.ceil((double) (((float) i3) / ˊ));
    }

    private float ˊ(j jVar, mq mqVar) {
        View view = null;
        int i = ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED;
        int ˈ = jVar.ˈ();
        if (ˈ == 0) {
            return 1.0f;
        }
        int i2 = 0;
        View view2 = null;
        int i3 = Integer.MIN_VALUE;
        while (i2 < ˈ) {
            View view3;
            View ᐝ = jVar.ᐝ(i2);
            int ˎ = jVar.ˎ(ᐝ);
            if (ˎ == -1) {
                ˎ = i;
                view3 = view;
                view = view2;
            } else {
                if (ˎ < i) {
                    i = ˎ;
                    view2 = ᐝ;
                }
                if (ˎ > i3) {
                    i3 = ˎ;
                    view = view2;
                    ˎ = i;
                    view3 = ᐝ;
                } else {
                    ˎ = i;
                    view3 = view;
                    view = view2;
                }
            }
            i2++;
            view2 = view;
            view = view3;
            i = ˎ;
        }
        if (view2 == null || view == null) {
            return 1.0f;
        }
        ˎ = Math.max(mqVar.ॱ(view2), mqVar.ॱ(view)) - Math.min(mqVar.ˋ(view2), mqVar.ˋ(view));
        if (ˎ == 0) {
            return 1.0f;
        }
        return (((float) ˎ) * 1.0f) / ((float) ((i3 - i) + 1));
    }
}
